package com.suep.system.mapper;

import com.suep.system.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 插入用户信息
     * @param user 用户实体类
     * @return 插入成功的记录数
     */
    @Insert("INSERT INTO `user` (`id`, `username`, `password`, `nickname`, `phone`, `email`, `profile`, `state`, `create_time`) " +
            "VALUES (#{id}, #{username}, #{password}, #{nickname}, #{phone}, #{email}, #{profile}, #{state}, #{createTime})")
    Integer insertUser(User user);
    /**
     * 根据 ID 查询用户信息
     * @param id 用户 ID
     * @return 用户实体类
     */
    @Select("SELECT * FROM `user` WHERE `id` = #{id}")
    User selectUserById(Long id);




    @Select("SELECT * FROM `user` WHERE `username` = #{username}")
    User selectUserByUsername(String username);
    /**
     * 查询所有用户信息
     * @return 用户列表
     */
    @Select("SELECT * FROM `user`")
    List<User> selectAllUsers();
    /**
     * 更新用户信息
     * @param user 用户实体类
     * @return 更新成功的记录数
     */
    @Update("UPDATE `user` SET `username` = #{username}, `password` = #{password}, `nickname` = #{nickname}, " +
            "`phone` = #{phone}, `email` = #{email}, `profile` = #{profile}, `state` = #{state}, `create_time` = #{createTime} " +
            "WHERE `id` = #{id}")
    Integer updateUser(User user);
    /**
     * 根据 ID 删除用户信息
     * @param id 用户 ID
     * @return 删除成功的记录数
     */
    @Delete("DELETE FROM `user` WHERE `id` = #{id}")
    Integer deleteUserById(Long id);
}
